package what.basic.list;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Jcomboboxmodel {
	String[] s={"abdd","dllww","0x0d","dosdd","e0033"};
	Jcomboboxmodel(){
		JFrame jf=new JFrame("jcomboboxmodel");
		Container cp=jf.getContentPane();
		ComboBoxModel cm=new Usercomboboxmodel();
		JComboBox cmb=new JComboBox(cm);
		cmb.setBorder(BorderFactory.createTitledBorder("who is your good friend"));
		cp.add(cmb);
		jf.pack();
		jf.setVisible(true);
		jf.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		});
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Jcomboboxmodel();
	}
	class Usercomboboxmodel extends AbstractListModel implements ComboBoxModel
	{
		String item=null;

		@Override
		
		public Object getElementAt(int index) {
			// TODO Auto-generated method stub
			return s[index++];
		}
			public int getSize() {
				// TODO Auto-generated method stub
				return s.length;
			}
			public void setSelectedItem(Object anItem) {
				item=(String)anItem;
			}
			public Object getSelectedItem() {
			// TODO Auto-generated method stub
			return item;
		}
	}
}
